package java8;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @author jiangz
 * @since 2020年9月18日 上午9:32:45
 * 
 * Java 8 特征
 */
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		Arrays.asList("a", "b", "c").forEach(e -> System.out.println(e));

		Formula formula = new Formula() {

			@Override
			public double calculate(double value) {
				return value * 100;
			}
		};
		System.out.println(formula.calculate(12));
		System.out.println(formula.sqrt(16));

		formula = value -> value * 200;
		System.out.println(formula.calculate(12));
		System.out.println(formula.sqrt(16));

		// 排序
		List<String> notOrdered = Arrays.asList("d", "c", "a", "b");
		notOrdered.forEach((String e) -> System.out.println(e));

		Collections.sort(notOrdered, (String a, String b) -> a.compareTo(b));
		notOrdered.forEach((String e) -> System.out.println(e));

		System.out.println("2.compareTo(3)" + new Integer(2).compareTo(new Integer(3)));
		System.out.println("a.compareTo(b)" + "a".compareTo("b"));

		Function<String> function = (String e) -> Integer.parseInt(e);
		System.out.println(function.convert("1234"));

		PeopleFactory pf = People::new;
		pf.create("xinxin", 18);

		List<String> notO = Arrays.asList("aa", "ab", "ba");
		notO.stream().filter((String s) -> s.startsWith("a")).forEach(s -> System.err.println(s));

	}

	interface PeopleFactory {
		People create(String name, Integer age);
	}
}
